

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>cup.util package &mdash; Cup 3.2.19 documentation</title>
  

  
  
  
  

  

  
  
    

  

  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="cup.web package" href="cup.web.html" />
    <link rel="prev" title="cup.storage package" href="cup.storage.html" /> 

  
  <script src="_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="index.html" class="icon icon-home"> Cup
          

          
          </a>

          
            
            
              <div class="version">
                3.2.0
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="cup.html">cup package</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="cup.html#subpackages">Subpackages</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="cup.net.html">cup.net package</a></li>
<li class="toctree-l3"><a class="reference internal" href="cup.res.html">cup.res package</a></li>
<li class="toctree-l3"><a class="reference internal" href="cup.services.html">cup.services package</a></li>
<li class="toctree-l3"><a class="reference internal" href="cup.shell.html">cup.shell package</a></li>
<li class="toctree-l3"><a class="reference internal" href="cup.storage.html">cup.storage package</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">cup.util package</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#submodules">Submodules</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.util.conf">cup.util.conf module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.util.constants">cup.util.constants module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.util.context">cup.util.context module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.util.misc">cup.util.misc module</a></li>
<li class="toctree-l4"><a class="reference internal" href="#module-cup.util">Module contents</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="cup.web.html">cup.web package</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#submodules">Submodules</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.cache">cup.cache module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.const">cup.const module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.decorators">cup.decorators module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.err">cup.err module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.exfile">cup.exfile module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.flag">cup.flag module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.log">cup.log module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.mail">cup.mail module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.platforms">cup.platforms module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.thread">cup.thread module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.timeplus">cup.timeplus module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.unittest">cup.unittest module</a></li>
<li class="toctree-l2"><a class="reference internal" href="cup.html#module-cup.version">cup.version module</a></li>
</ul>
</li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">Cup</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
          <li><a href="cup.html">cup package</a> &raquo;</li>
        
      <li>cup.util package</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/cup.util.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="cup-util-package">
<h1>cup.util package<a class="headerlink" href="#cup-util-package" title="Permalink to this headline">¶</a></h1>
<div class="section" id="submodules">
<h2>Submodules<a class="headerlink" href="#submodules" title="Permalink to this headline">¶</a></h2>
</div>
<div class="section" id="module-cup.util.conf">
<span id="cup-util-conf-module"></span><h2>cup.util.conf module<a class="headerlink" href="#module-cup.util.conf" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body">Complex and constructive conf support</td>
</tr>
</tbody>
</table>
<dl class="class">
<dt id="cup.util.conf.Configure2Dict">
<em class="property">class </em><code class="descclassname">cup.util.conf.</code><code class="descname">Configure2Dict</code><span class="sig-paren">(</span><em>configure_file</em>, <em>remove_comments=True</em>, <em>separator=':'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/conf.html#Configure2Dict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.conf.Configure2Dict" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Configure2Dict support conf features below:</p>
<ol class="arabic">
<li><p class="first">comments</p>
<blockquote>
<div><p>As we support access/modify comments in a conf file, you should obey
rules below:</p>
<p>Comment closely above the object you want to comment.
Do NOT comment after the line.</p>
<p>Otherwise, you might get/set a wrong comment above the object.</p>
</div></blockquote>
</li>
<li><p class="first">sections</p>
<blockquote>
<div><p>2.1 global section</p>
<blockquote>
<div><ul class="simple">
<li>if key:value is not under any [section],
it is under the global layerby default</li>
<li>global section is the 0th layer section</li>
</ul>
<p>e.g.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># test.conf</span>
<span class="k">global</span><span class="o">-</span><span class="n">key</span><span class="p">:</span> <span class="n">value</span>
<span class="k">global</span><span class="o">-</span><span class="n">key1</span><span class="p">:</span> <span class="n">value1</span>
</pre></div>
</div>
</div></blockquote>
<p>2.2 child section</p>
<blockquote>
<div><ul class="simple">
<li>[section1] means a child section under Global. And it’s the
1st layer section</li>
<li>[.section2] means a child section under the nearest section
above. It’s the 2nd layer section.</li>
<li>[..section3] means a child section under the nearest section
above. And the prefix .. means it is the 3rd layer section</li>
</ul>
<p>e.g.: test.conf:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">global</span><span class="o">-</span><span class="n">key</span><span class="p">:</span> <span class="n">value</span>
<span class="p">[</span><span class="n">section</span><span class="p">]</span>
    <span class="n">host</span><span class="p">:</span>  <span class="n">abc</span><span class="o">.</span><span class="n">com</span>
    <span class="n">port</span><span class="p">:</span>  <span class="mi">8080</span>
    <span class="p">[</span><span class="o">.</span><span class="n">section_child</span><span class="p">]</span>
        <span class="n">child_key</span><span class="p">:</span> <span class="n">child_value</span>
        <span class="p">[</span><span class="o">..</span><span class="n">section_child_child</span><span class="p">]</span>
            <span class="n">control</span><span class="p">:</span> <span class="n">ssh</span>
            <span class="p">[</span><span class="o">...</span><span class="n">section_child_child_child</span><span class="p">]</span>
                <span class="n">wow_key</span><span class="p">:</span>  <span class="n">wow_value</span>
</pre></div>
</div>
</div></blockquote>
<p>2.3 section access method</p>
<blockquote>
<div><p>get_dict method will convert conf into a ConfDict which is derived
from python dict.</p>
<ul class="simple">
<li>Access the section with confdict[‘section’][‘section-child’].</li>
<li>Access the section with confdict.get_ex(‘section’) with (value,
comments)</li>
</ul>
</div></blockquote>
</div></blockquote>
</li>
<li><p class="first">key:value and key:value array</p>
<blockquote>
<div><p>3.1 key:value</p>
<blockquote>
<div><p>key:value can be set under Global section which is closely after the
1st line with no [section] above.</p>
<p>key:value can also be set under sections.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># test.conf</span>
<span class="n">key1</span><span class="p">:</span> <span class="n">value1</span>
<span class="p">[</span><span class="n">section</span><span class="p">]</span>
    <span class="n">key_section</span><span class="p">:</span> <span class="n">value_in_section</span>
    <span class="p">[</span><span class="o">.</span><span class="n">seciton</span><span class="p">]</span>
        <span class="n">key_section_child</span><span class="p">:</span> <span class="n">value_section_child</span>
</pre></div>
</div>
</div></blockquote>
<p>3.2 key:value arrays</p>
<blockquote>
<div><p>key:value arrays can be access with confdict[‘section’][‘disk’].
You will get a ConfList derived from python list.</p>
</div></blockquote>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># test.conf</span>
<span class="c1"># Global layer, key:value</span>
<span class="n">host</span><span class="p">:</span> <span class="n">abc</span><span class="o">.</span><span class="n">com</span>
<span class="n">port</span><span class="p">:</span> <span class="mi">12345</span>
<span class="c1"># 1st layer [monitor]</span>
<span class="nd">@disk</span><span class="p">:</span> <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">data0</span>
<span class="nd">@disk</span><span class="p">:</span> <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">data1</span>
<span class="p">[</span><span class="n">section</span><span class="p">]</span>
    <span class="nd">@disk</span><span class="p">:</span> <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">disk</span><span class="o">/</span><span class="n">disk1</span>
    <span class="nd">@disk</span><span class="p">:</span> <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">disk</span><span class="o">/</span><span class="n">disk2</span>
</pre></div>
</div>
</div></blockquote>
</li>
<li><p class="first">Example</p>
</li>
</ol>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># test.conf</span>
<span class="c1"># Global layer, key:value</span>
<span class="n">host</span><span class="p">:</span> <span class="n">abc</span><span class="o">.</span><span class="n">com</span>
<span class="n">port</span><span class="p">:</span> <span class="mi">12345</span>
<span class="c1"># 1st layer [monitor]</span>
<span class="nd">@disk</span><span class="p">:</span> <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">data0</span>
<span class="nd">@disk</span><span class="p">:</span> <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">data1</span>
<span class="p">[</span><span class="n">section</span><span class="p">]</span>
    <span class="nd">@disk</span><span class="p">:</span> <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">disk</span><span class="o">/</span><span class="n">disk1</span>
    <span class="nd">@disk</span><span class="p">:</span> <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">disk</span><span class="o">/</span><span class="n">disk2</span>

<span class="p">[</span><span class="n">monitor</span><span class="p">]</span>
    <span class="n">timeout</span><span class="p">:</span> <span class="mi">100</span>
    <span class="n">regex</span><span class="p">:</span>  <span class="n">sshd</span>
    <span class="c1"># 2nd layer that belongs to [monitor]</span>
    <span class="p">[</span><span class="o">.</span><span class="n">timeout</span><span class="p">]</span>
        <span class="c1"># key:value in timeout</span>
        <span class="nb">max</span><span class="p">:</span> <span class="mi">100</span>
        <span class="c1"># 3rd layer that belongs to [monitor] [timeout]</span>
        <span class="p">[</span><span class="o">..</span><span class="n">handler</span><span class="p">]</span>
            <span class="n">default</span><span class="p">:</span> <span class="n">exit</span>

<span class="c1"># codes represent accessing conf and modifying conf</span>
<span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">print_function</span>
<span class="kn">from</span> <span class="nn">cup.util</span> <span class="k">import</span> <span class="n">conf</span>
<span class="c1"># 1. read from test.conf</span>
<span class="n">confdict</span> <span class="o">=</span> <span class="n">conf</span><span class="o">.</span><span class="n">Configure2Dict</span><span class="p">(</span><span class="s1">&#39;test.conf&#39;</span><span class="p">,</span> <span class="n">separator</span><span class="o">=</span><span class="s1">&#39;:&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">get_dict</span><span class="p">()</span>
<span class="nb">print</span><span class="p">(</span><span class="n">confdict</span><span class="p">[</span><span class="s1">&#39;host&#39;</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="n">confdict</span><span class="p">[</span><span class="s1">&#39;port&#39;</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="n">confdict</span><span class="p">[</span><span class="s1">&#39;section&#39;</span><span class="p">][</span><span class="s1">&#39;disk&#39;</span><span class="p">])</span>
<span class="nb">print</span><span class="p">(</span><span class="n">confdict</span><span class="p">[</span><span class="s1">&#39;monitor&#39;</span><span class="p">][</span><span class="s1">&#39;timeout&#39;</span><span class="p">][</span><span class="s1">&#39;handler&#39;</span><span class="p">])</span>
<span class="c1"># 2. Change something and write back to test.conf</span>
<span class="n">confdict</span><span class="p">[</span><span class="s1">&#39;port&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;10085&#39;</span>
<span class="n">confdict</span><span class="p">[</span><span class="s1">&#39;monitor&#39;</span><span class="p">][</span><span class="s1">&#39;timeout&#39;</span><span class="p">][</span><span class="s1">&#39;handler&#39;</span><span class="p">][</span><span class="s1">&#39;default&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;stop&#39;</span>
<span class="n">confobj</span> <span class="o">=</span> <span class="n">conf</span><span class="o">.</span><span class="n">Dict2Configure</span><span class="p">(</span><span class="n">confdict</span><span class="p">,</span> <span class="n">separator</span><span class="o">=</span><span class="s1">&#39;:&#39;</span><span class="p">)</span>
<span class="n">confobj</span><span class="o">.</span><span class="n">write_conf</span><span class="p">(</span><span class="s1">&#39;./test.conf.new&#39;</span><span class="p">)</span>
</pre></div>
</div>
<dl class="method">
<dt id="cup.util.conf.Configure2Dict.get_dict">
<code class="descname">get_dict</code><span class="sig-paren">(</span><em>ignore_error=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/conf.html#Configure2Dict.get_dict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.conf.Configure2Dict.get_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>get conf_dict which you can use to access conf info.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>ignore_error</strong> – True, CUP will parse the conf file without catching exceptions</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cup.util.conf.Dict2Configure">
<em class="property">class </em><code class="descclassname">cup.util.conf.</code><code class="descname">Dict2Configure</code><span class="sig-paren">(</span><em>conf_dict</em>, <em>separator=':'</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/conf.html#Dict2Configure"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.conf.Dict2Configure" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>Convert Dict into Configure.
You can convert a ConfDict or python dict into a conf file.</p>
<dl class="method">
<dt id="cup.util.conf.Dict2Configure.set_dict">
<code class="descname">set_dict</code><span class="sig-paren">(</span><em>conf_dict</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/conf.html#Dict2Configure.set_dict"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.conf.Dict2Configure.set_dict" title="Permalink to this definition">¶</a></dt>
<dd><p>set a new conf_dict</p>
</dd></dl>

<dl class="method">
<dt id="cup.util.conf.Dict2Configure.write_conf">
<code class="descname">write_conf</code><span class="sig-paren">(</span><em>conf_file</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/conf.html#Dict2Configure.write_conf"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.conf.Dict2Configure.write_conf" title="Permalink to this definition">¶</a></dt>
<dd><p>write the conf into of the dict into a conf_file</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cup.util.conf.HdfsXmlConf">
<em class="property">class </em><code class="descclassname">cup.util.conf.</code><code class="descname">HdfsXmlConf</code><span class="sig-paren">(</span><em>filepath</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/conf.html#HdfsXmlConf"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.conf.HdfsXmlConf" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>hdfs xmlconf modifier.</p>
<p>Example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># modify and write new conf into hadoop-site.xmlconf</span>
<span class="n">xmlobj</span> <span class="o">=</span> <span class="n">xmlconf</span><span class="o">.</span><span class="n">HdfsXmlConf</span><span class="p">(</span><span class="n">xmlfile</span><span class="p">)</span>

<span class="c1"># get hdfs conf items into a python dict</span>
<span class="n">key_values</span> <span class="o">=</span> <span class="n">xmlobj</span><span class="o">.</span><span class="n">get_items</span><span class="p">()</span>

<span class="c1"># modify hdfs conf items</span>
<span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_confdict</span><span class="p">[</span><span class="s1">&#39;journalnode&#39;</span><span class="p">][</span><span class="s1">&#39;hadoop_site&#39;</span><span class="p">]:</span>
    <span class="k">if</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">key_values</span><span class="p">:</span>
        <span class="n">key_values</span><span class="p">[</span><span class="n">name</span><span class="p">][</span><span class="s1">&#39;value&#39;</span><span class="p">]</span> <span class="o">=</span>                 <span class="bp">self</span><span class="o">.</span><span class="n">_confdict</span><span class="p">[</span><span class="s1">&#39;journalnode&#39;</span><span class="p">][</span><span class="s1">&#39;hadoop_site&#39;</span><span class="p">][</span><span class="n">name</span><span class="p">]</span>
<span class="k">else</span><span class="p">:</span>
    <span class="n">key_values</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;value&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">_confdict</span><span class="p">[</span><span class="s1">&#39;journalnode&#39;</span><span class="p">][</span><span class="s1">&#39;hadoop_site&#39;</span><span class="p">][</span><span class="n">name</span><span class="p">],</span>
        <span class="s1">&#39;description&#39;</span><span class="p">:</span> <span class="s1">&#39; &#39;</span>
    <span class="p">}</span>
<span class="n">hosts</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_confdict</span><span class="p">[</span><span class="s1">&#39;journalnode&#39;</span><span class="p">][</span><span class="s1">&#39;host&#39;</span><span class="p">])</span>
<span class="n">key_values</span><span class="p">[</span><span class="s1">&#39;dfs.journalnode.hosts&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s1">&#39;value&#39;</span><span class="p">:</span> <span class="n">hosts</span><span class="p">,</span> <span class="s1">&#39;description&#39;</span><span class="p">:</span><span class="s1">&#39; journalnode hosts&#39;</span>
<span class="p">}</span>

<span class="c1"># write back conf items with new values</span>
<span class="n">xmlobj</span><span class="o">.</span><span class="n">write_conf</span><span class="p">(</span><span class="n">key_values</span><span class="p">)</span>
</pre></div>
</div>
<dl class="method">
<dt id="cup.util.conf.HdfsXmlConf.get_items">
<code class="descname">get_items</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/conf.html#HdfsXmlConf.get_items"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.conf.HdfsXmlConf.get_items" title="Permalink to this definition">¶</a></dt>
<dd><p>return hadoop config items as a dict.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body"><div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="s1">&#39;dfs.datanode.max.xcievers&#39;</span><span class="p">:</span>  <span class="p">{</span>
        <span class="s1">&#39;value&#39;</span><span class="p">:</span> <span class="s1">&#39;true&#39;</span><span class="p">,</span> <span class="s1">&#39;description&#39;</span><span class="p">:</span> <span class="s1">&#39;xxxxxxxxxx&#39;</span>
    <span class="p">},</span>
    <span class="o">......</span>
<span class="p">}</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="cup.util.conf.HdfsXmlConf.write_conf">
<code class="descname">write_conf</code><span class="sig-paren">(</span><em>kvs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/conf.html#HdfsXmlConf.write_conf"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.conf.HdfsXmlConf.write_conf" title="Permalink to this definition">¶</a></dt>
<dd><p>update config items with a dict kvs. Refer to the example above.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>kvs</strong> – <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
    <span class="n">key</span> <span class="p">:</span> <span class="p">{</span> <span class="s1">&#39;value&#39;</span><span class="p">:</span> <span class="n">value</span><span class="p">,</span> <span class="s1">&#39;description&#39;</span><span class="p">:</span> <span class="s1">&#39;description&#39;</span><span class="p">},</span>
    <span class="o">......</span>
<span class="p">}</span>
</pre></div>
</div>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-cup.util.constants">
<span id="cup-util-constants-module"></span><h2>cup.util.constants module<a class="headerlink" href="#module-cup.util.constants" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body"><p class="first">constant related module
<em>test-case-name: twisted.python.test.test_constants</em>
Copyright (c) Twisted Matrix Laboratories.
See LICENSE for details.</p>
</td>
</tr>
<tr class="field-even field"><th class="field-name">license:</th><td class="field-body"><p class="first">CUP dev team modified and redistrbuted this module,
according to MIT license
(<a class="reference external" href="http://opensource.org/licenses/mit-license.php">http://opensource.org/licenses/mit-license.php</a>)
that Twisted lib obeys.</p>
<p>If any concern, plz contact <a class="reference external" href="mailto:mythmgn&#37;&#52;&#48;gmail&#46;com">mythmgn<span>&#64;</span>gmail<span>&#46;</span>com</a>.</p>
<p>Mit License applied for twisted</p>
<blockquote class="last">
<div><p><a class="reference external" href="http://www.opensource.org/licenses/mit-license.php">http://www.opensource.org/licenses/mit-license.php</a>
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and associated
documentation files (the “Software”),
to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:</p>
<p>The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.</p>
<p>THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<dl class="class">
<dt id="cup.util.constants.NamedConstant">
<em class="property">class </em><code class="descclassname">cup.util.constants.</code><code class="descname">NamedConstant</code><a class="reference internal" href="_modules/cup/util/constants.html#NamedConstant"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.constants.NamedConstant" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">cup.util.constants._Constant</span></code></p>
<p>L{NamedConstant} defines an attribute to be a named constant within a
collection defined by a L{Names} subclass.</p>
<p>L{NamedConstant} is only for use in the definition of L{Names}
subclasses.  Do not instantiate L{NamedConstant} elsewhere and do not
subclass it.</p>
</dd></dl>

<dl class="class">
<dt id="cup.util.constants.ValueConstant">
<em class="property">class </em><code class="descclassname">cup.util.constants.</code><code class="descname">ValueConstant</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/constants.html#ValueConstant"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.constants.ValueConstant" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">cup.util.constants._Constant</span></code></p>
<p>L{ValueConstant} defines an attribute to be a named constant within a
collection defined by a L{Values} subclass.</p>
<p>L{ValueConstant} is only for use in the definition of L{Values} subclasses.
Do not instantiate L{ValueConstant} elsewhere and do not subclass it.</p>
</dd></dl>

<dl class="class">
<dt id="cup.util.constants.FlagConstant">
<em class="property">class </em><code class="descclassname">cup.util.constants.</code><code class="descname">FlagConstant</code><span class="sig-paren">(</span><em>value=None</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/constants.html#FlagConstant"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.constants.FlagConstant" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">cup.util.constants._Constant</span></code></p>
<p>L{FlagConstant} defines an attribute to be a flag constant within a
collection defined by a L{Flags} subclass.</p>
<p>L{FlagConstant} is only for use in the definition of L{Flags} subclasses.
Do not instantiate L{FlagConstant} elsewhere and do not subclass it.</p>
</dd></dl>

<dl class="class">
<dt id="cup.util.constants.Names">
<em class="property">class </em><code class="descclassname">cup.util.constants.</code><code class="descname">Names</code><a class="reference internal" href="_modules/cup/util/constants.html#Names"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.constants.Names" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">cup.util.constants._ConstantsContainer</span></code></p>
<p>A L{Names} subclass contains constants which differ only in their names and
identities.</p>
</dd></dl>

<dl class="class">
<dt id="cup.util.constants.Values">
<em class="property">class </em><code class="descclassname">cup.util.constants.</code><code class="descname">Values</code><a class="reference internal" href="_modules/cup/util/constants.html#Values"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.constants.Values" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">cup.util.constants._ConstantsContainer</span></code></p>
<p>A L{Values} subclass contains constants which are associated with arbitrary
values.</p>
<dl class="classmethod">
<dt id="cup.util.constants.Values.lookupByValue">
<em class="property">classmethod </em><code class="descname">lookupByValue</code><span class="sig-paren">(</span><em>value</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/constants.html#Values.lookupByValue"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.constants.Values.lookupByValue" title="Permalink to this definition">¶</a></dt>
<dd><p>Retrieve a constant by its value or raise a C{ValueError} if there is
no constant associated with that value.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>value</strong> – The value of one of the constants defined by C{cls}.</td>
</tr>
<tr class="field-even field"><th class="field-name">Raises:</th><td class="field-body"><strong>ValueError</strong> – If C{value} is not the value of one of the constants
defined by C{cls}.</td>
</tr>
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">The L{ValueConstant} associated with C{value}.</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cup.util.constants.Flags">
<em class="property">class </em><code class="descclassname">cup.util.constants.</code><code class="descname">Flags</code><a class="reference internal" href="_modules/cup/util/constants.html#Flags"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.constants.Flags" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#cup.util.constants.Values" title="cup.util.constants.Values"><code class="xref py py-class docutils literal notranslate"><span class="pre">cup.util.constants.Values</span></code></a></p>
<p>A L{Flags} subclass contains constants which can be combined using the
common bitwise operators (C{|}, C{&amp;}, etc) similar to a I{bitvector} from a
language like C.</p>
</dd></dl>

</div>
<div class="section" id="module-cup.util.context">
<span id="cup-util-context-module"></span><h2>cup.util.context module<a class="headerlink" href="#module-cup.util.context" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body">context for threadpool</td>
</tr>
</tbody>
</table>
<dl class="class">
<dt id="cup.util.context.ContextManager">
<em class="property">class </em><code class="descclassname">cup.util.context.</code><code class="descname">ContextManager</code><a class="reference internal" href="_modules/cup/util/context.html#ContextManager"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.context.ContextManager" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>context for function call stack</p>
<dl class="method">
<dt id="cup.util.context.ContextManager.call_with_context">
<code class="descname">call_with_context</code><span class="sig-paren">(</span><em>new_context</em>, <em>func</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/context.html#ContextManager.call_with_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.context.ContextManager.call_with_context" title="Permalink to this definition">¶</a></dt>
<dd><p>context is a {}</p>
</dd></dl>

<dl class="method">
<dt id="cup.util.context.ContextManager.get_context">
<code class="descname">get_context</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/context.html#ContextManager.get_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.context.ContextManager.get_context" title="Permalink to this definition">¶</a></dt>
<dd><p>get the context that has the key</p>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="cup.util.context.ContextTracker4Thread">
<em class="property">class </em><code class="descclassname">cup.util.context.</code><code class="descname">ContextTracker4Thread</code><a class="reference internal" href="_modules/cup/util/context.html#ContextTracker4Thread"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.context.ContextTracker4Thread" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>thread switch tracker</p>
<dl class="method">
<dt id="cup.util.context.ContextTracker4Thread.call_with_context">
<code class="descname">call_with_context</code><span class="sig-paren">(</span><em>context</em>, <em>func</em>, <em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/context.html#ContextTracker4Thread.call_with_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.context.ContextTracker4Thread.call_with_context" title="Permalink to this definition">¶</a></dt>
<dd><p>call [func] and set up a context with it</p>
</dd></dl>

<dl class="method">
<dt id="cup.util.context.ContextTracker4Thread.current_context">
<code class="descname">current_context</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/context.html#ContextTracker4Thread.current_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.context.ContextTracker4Thread.current_context" title="Permalink to this definition">¶</a></dt>
<dd><p>get current context</p>
</dd></dl>

<dl class="method">
<dt id="cup.util.context.ContextTracker4Thread.get_context">
<code class="descname">get_context</code><span class="sig-paren">(</span><em>key</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/context.html#ContextTracker4Thread.get_context"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.context.ContextTracker4Thread.get_context" title="Permalink to this definition">¶</a></dt>
<dd><p>get the context by key</p>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="module-cup.util.misc">
<span id="cup-util-misc-module"></span><h2>cup.util.misc module<a class="headerlink" href="#module-cup.util.misc" title="Permalink to this headline">¶</a></h2>
<p>misc classes for internal use</p>
<dl class="class">
<dt id="cup.util.misc.CAck">
<em class="property">class </em><code class="descclassname">cup.util.misc.</code><code class="descname">CAck</code><span class="sig-paren">(</span><em>binit=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/misc.html#CAck"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.misc.CAck" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>ack class</p>
<dl class="method">
<dt id="cup.util.misc.CAck.getack_infobool">
<code class="descname">getack_infobool</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/misc.html#CAck.getack_infobool"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.misc.CAck.getack_infobool" title="Permalink to this definition">¶</a></dt>
<dd><p>get bool info</p>
</dd></dl>

<dl class="method">
<dt id="cup.util.misc.CAck.setack_infobool">
<code class="descname">setack_infobool</code><span class="sig-paren">(</span><em>binit=False</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/misc.html#CAck.setack_infobool"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.misc.CAck.setack_infobool" title="Permalink to this definition">¶</a></dt>
<dd><p>set bool info</p>
</dd></dl>

</dd></dl>

<dl class="function">
<dt id="cup.util.misc.check_not_none">
<code class="descclassname">cup.util.misc.</code><code class="descname">check_not_none</code><span class="sig-paren">(</span><em>param</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/misc.html#check_not_none"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.misc.check_not_none" title="Permalink to this definition">¶</a></dt>
<dd><p>check param is not None</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Raise:</th><td class="field-body">NameError if param is None</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cup.util.misc.check_type">
<code class="descclassname">cup.util.misc.</code><code class="descname">check_type</code><span class="sig-paren">(</span><em>param</em>, <em>expect</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/misc.html#check_type"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.misc.check_type" title="Permalink to this definition">¶</a></dt>
<dd><p>check type of the param is as the same as expect’s</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Raise:</th><td class="field-body">raise TypeError if it’s not the same</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cup.util.misc.get_filename">
<code class="descclassname">cup.util.misc.</code><code class="descname">get_filename</code><span class="sig-paren">(</span><em>backstep=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/misc.html#get_filename"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.misc.get_filename" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the file name of the current code line.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>backstep</strong> – will go backward (one layer) from the current function call stack</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cup.util.misc.get_funcname">
<code class="descclassname">cup.util.misc.</code><code class="descname">get_funcname</code><span class="sig-paren">(</span><em>backstep=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/misc.html#get_funcname"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.misc.get_funcname" title="Permalink to this definition">¶</a></dt>
<dd><p>get funcname of the current code line</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>backstep</strong> – will go backward (one layer) from the current function call stack</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="function">
<dt id="cup.util.misc.get_lineno">
<code class="descclassname">cup.util.misc.</code><code class="descname">get_lineno</code><span class="sig-paren">(</span><em>backstep=0</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util/misc.html#get_lineno"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.misc.get_lineno" title="Permalink to this definition">¶</a></dt>
<dd><p>Get the line number of the current code line</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>backstep</strong> – will go backward (one layer) from the current function call stack</td>
</tr>
</tbody>
</table>
</dd></dl>

</div>
<div class="section" id="module-cup.util">
<span id="module-contents"></span><h2>Module contents<a class="headerlink" href="#module-cup.util" title="Permalink to this headline">¶</a></h2>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">description:</th><td class="field-body">utilization related module</td>
</tr>
</tbody>
</table>
<dl class="function">
<dt id="cup.util.check_not_none">
<code class="descclassname">cup.util.</code><code class="descname">check_not_none</code><span class="sig-paren">(</span><em>param</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util.html#check_not_none"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.check_not_none" title="Permalink to this definition">¶</a></dt>
<dd><p>deprecated. Recommand using misc.check_not_none</p>
</dd></dl>

<dl class="function">
<dt id="cup.util.check_type">
<code class="descclassname">cup.util.</code><code class="descname">check_type</code><span class="sig-paren">(</span><em>param</em>, <em>expect</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/cup/util.html#check_type"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#cup.util.check_type" title="Permalink to this definition">¶</a></dt>
<dd><p>deprecated. Recommand using misc.check_type in cup.util</p>
</dd></dl>

</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="cup.web.html" class="btn btn-neutral float-right" title="cup.web package" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="cup.storage.html" class="btn btn-neutral" title="cup.storage package" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2020, CUP-DEV.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'./',
            VERSION:'3.2.19',
            LANGUAGE:'en',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true,
            SOURCELINK_SUFFIX: '.txt'
        };
    </script>
      <script type="text/javascript" src="_static/jquery.js"></script>
      <script type="text/javascript" src="_static/underscore.js"></script>
      <script type="text/javascript" src="_static/doctools.js"></script>
      <script type="text/javascript" src="_static/language_data.js"></script>

  

  <script type="text/javascript" src="_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>